package com.ruoyi.web.controller.wallet;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.wallet.domain.Wallet;
import com.ruoyi.wallet.service.IWalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户钱包Controller
 * 
 * @author 张富饶
 * @date 2025-05-20
 */
@RestController
@RequestMapping("/wallet/wallet")
public class WalletController extends BaseController
{
    @Autowired
    private IWalletService walletService;

    /**
     * 查询用户钱包列表
     */
    @PreAuthorize("@ss.hasPermi('wallet:wallet:list')")
    @GetMapping("/list")
    public TableDataInfo list(Wallet wallet)
    {
        startPage();
        List<Wallet> list = walletService.selectWalletList(wallet);
        return getDataTable(list);
    }

    /**
     * 导出用户钱包列表
     */
    @PreAuthorize("@ss.hasPermi('wallet:wallet:export')")
    @Log(title = "用户钱包", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Wallet wallet)
    {
        List<Wallet> list = walletService.selectWalletList(wallet);
        ExcelUtil<Wallet> util = new ExcelUtil<Wallet>(Wallet.class);
        util.exportExcel(response, list, "用户钱包数据");
    }

    /**
     * 获取用户钱包详细信息
     */
    @PreAuthorize("@ss.hasPermi('wallet:wallet:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(walletService.selectWalletById(id));
    }

    /**
     * 新增用户钱包
     */
    @PreAuthorize("@ss.hasPermi('wallet:wallet:add')")
    @Log(title = "用户钱包", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Wallet wallet)
    {
        return toAjax(walletService.insertWallet(wallet));
    }

    /**
     * 修改用户钱包
     */
    @PreAuthorize("@ss.hasPermi('wallet:wallet:edit')")
    @Log(title = "用户钱包", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Wallet wallet)
    {
        return toAjax(walletService.updateWallet(wallet));
    }

    /**
     * 删除用户钱包
     */
    @PreAuthorize("@ss.hasPermi('wallet:wallet:remove')")
    @Log(title = "用户钱包", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(walletService.deleteWalletByIds(ids));
    }
}
